<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>检查权限管理菜单</title>
    <style>
        body { font-family: Arial; padding: 20px; }
        table { border-collapse: collapse; width: 100%; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #4CAF50; color: white; }
        .error { color: red; }
        .success { color: green; }
    </style>
</head>
<body>
    <h1>检查权限管理菜单结构</h1>
    
    <?php
    $host = '113.44.136.17';
    $port = 3306;
    $database = 'qiandao';
    $username = 'qiandao';
    $password = 'NGbks3HWx5PhSxDX';
    
    try {
        $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        echo "<h2>权限管理菜单结构</h2>";
        
        $stmt = $pdo->query("
            SELECT id, pid, title, url, node, status, sort
            FROM system_menu
            WHERE id = 9 OR pid = 9 OR pid IN (SELECT id FROM system_menu WHERE pid = 9)
            ORDER BY 
                CASE WHEN id = 9 THEN 0 WHEN pid = 9 THEN 1 ELSE 2 END,
                sort DESC, id ASC
        ");
        
        $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        echo "<table>";
        echo "<tr><th>ID</th><th>PID</th><th>标题</th><th>URL</th><th>NODE</th><th>状态</th><th>SORT</th><th>层级</th></tr>";
        
        $level2Count = 0;
        $level3Count = 0;
        
        foreach ($menus as $menu) {
            $level = '';
            if ($menu['pid'] == 0) {
                $level = '一级';
            } elseif ($menu['pid'] == 9) {
                $level = '二级';
                $level2Count++;
            } else {
                $level = '三级';
                $level3Count++;
            }
            
            $status = $menu['status'] == 1 ? '启用' : '禁用';
            
            echo "<tr>";
            echo "<td>{$menu['id']}</td>";
            echo "<td>{$menu['pid']}</td>";
            echo "<td>{$menu['title']}</td>";
            echo "<td>{$menu['url']}</td>";
            echo "<td>{$menu['node']}</td>";
            echo "<td>{$status}</td>";
            echo "<td>{$menu['sort']}</td>";
            echo "<td><strong>{$level}</strong></td>";
            echo "</tr>";
        }
        
        echo "</table>";
        
        echo "<h2>统计</h2>";
        echo "<p>二级菜单数量: <strong>{$level2Count}</strong></p>";
        echo "<p>三级菜单数量: <strong>{$level3Count}</strong></p>";
        
        if ($level3Count > 0) {
            echo "<p class='success'>✓ 有三级菜单，应该显示在左侧</p>";
        } else {
            echo "<p class='error'>❌ 没有三级菜单，会显示在顶部</p>";
        }
        
        // 检查是否有 URL 为 # 的二级菜单
        echo "<h2>问题诊断</h2>";
        
        $hasGroupMenu = false;
        foreach ($menus as $menu) {
            if ($menu['pid'] == 9 && $menu['url'] == '#') {
                $hasGroupMenu = true;
                echo "<p class='success'>✓ 找到分组菜单: {$menu['title']} (ID:{$menu['id']})</p>";
                
                // 检查这个分组下是否有子菜单
                $subCount = 0;
                foreach ($menus as $sub) {
                    if ($sub['pid'] == $menu['id']) {
                        $subCount++;
                    }
                }
                
                echo "<p>该分组下有 {$subCount} 个子菜单</p>";
            }
        }
        
        if (!$hasGroupMenu) {
            echo "<p class='error'>❌ 没有找到分组菜单（URL=#的二级菜单）</p>";
            echo "<p>这就是问题所在！需要创建一个分组菜单</p>";
        }
        
    } catch (PDOException $e) {
        echo "<p class='error'>数据库错误: " . $e->getMessage() . "</p>";
    }
    ?>
    
    <hr>
    <p><a href="javascript:location.reload()">刷新</a></p>
</body>
</html>

